package cn.zhku.user.web.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.zhku.user.entity.UserEntity;
import cn.zhku.user.service.UserException;
import cn.zhku.user.service.UserService;

/**
 * Servlet implementation class DelectServlet
 */
@WebServlet("/DelectServlet")
public class DeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	UserService userService = new UserService();  
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");//
		response.setContentType("text/html;charset=utf-8"); 
		ArrayList<UserEntity> userList = userService.query(); 
		request.setAttribute("userList", userList);
		request.getRequestDispatcher("list.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");//
		response.setContentType("text/html;charset=utf-8"); 
		String userId = request.getParameter("userId");
		try {
			userService.delete(Integer.parseInt(userId));
		} catch (UserException e) {
			
		}
		
		doGet( request, response);	
	}

}
